import Vue from 'vue'
import Router from 'vue-router'
// 导入动态路由
import dynamicRoute from '@/router/modules/dynamicRoute';
// import employees from '@/router/modules/employees';
// import approvals from '@/router/modules/approvals';
// import attendances from '@/router/modules/attendances';
// import departments from '@/router/modules/departments';
// import permission from '@/router/modules/permission';
// import salarys from '@/router/modules/salarys';
// import setting from '@/router/modules/setting';
// import social from '@/router/modules/social';

Vue.use(Router)

/* Layout */
import Layout from '@/layout'


export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' }
    }]
  },

  {
    path: '/import',
    component: Layout,
    hidden: true, // 隐藏在左侧菜单中
    children: [{
      path: '', // 二级路由path什么都不写 表示二级默认路由
      component: () => import('@/views/import')
    }]
  },

  // 404 page must be placed at the end !!!
  // { path: '*', redirect: '/404', hidden: true }
  {
    path: '/users',
    component: Layout,
    hidden: true,
    name: 'user',
    children: [
      {
        path: '/users/approvals',
        component: () => import('@/views/users/approvals'),
        name: 'usersApprovals',
        hidden: true,
        meta: {
          title: '用户'
        }
      },
      {
        path: '/users/info',
        component: () => import('@/views/users/info'),
        name: 'myInfo',
        hidden: true,
        meta: {
          title: '我的信息'
        }
      }
    ]
  }
]

// export const dynamicRoute = [employees, approvals, attendances, departments, permission, salarys, setting, social]

const createRouter = () => new Router({
  scrollBehavior: () => ({ y: 0 }),
  // 将静态路由和动态路由进行合并
  // routes: [...constantRoutes, ...dynamicRoute]
  routes: [...constantRoutes]
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
